package org.springblade.weixin.controller;


import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaUserService;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@NonDS
@RestController
@AllArgsConstructor
@RequestMapping("miniapp/user")
@Api(value = "微信小程序接口", tags = "小程序接口")
public class MiniappUserController {

	private final WxMaService wxMaService;

	@SneakyThrows
	@GetMapping("/phone-number")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "获取手机号码", notes = "获取用户绑定的手机号码")
	R<WxMaPhoneNumberInfo> getUserPhoneNumber(@ApiParam(value = "code",required = true) @RequestParam("code") String code) {
		WxMaUserService userService = wxMaService.getUserService();
		WxMaPhoneNumberInfo phoneNoInfo = userService.getNewPhoneNoInfo(code);
		return R.data(phoneNoInfo);
	}

}
